package com.rms.recruit_management_system.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.rms.recruit_management_system.mapper.TalentMapper;
import com.rms.recruit_management_system.mapper.TalentVoMapper;
import com.rms.recruit_management_system.utils.Result;
import com.rms.recruit_management_system.vo.TalentVo;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class TalentController {

    @Autowired
    private TalentVoMapper talentVoMapper;
    @Autowired
    private TalentMapper talentMapper;

    @RequestMapping("/talent/getTalentVoPage")
    public Result<?> selectTalentVoPage(@RequestParam(defaultValue = "1") int pageNum,
                                        @RequestParam(defaultValue = "10") int pageSize){
        Page<TalentVo> page = new Page<>();
        page.setCurrent(pageNum);
        page.setSize(pageSize);
        IPage<TalentVo> talentVoIPage = talentVoMapper.selectTalentPageWithJoins(page);
        return new Result<>(200, "success", talentVoIPage);
    }

    @RequestMapping("/talent/add")
    public Result<?> addToTalent(TalentVo talentVo){
        int result = talentMapper.insert(talentVo);
        return new Result<>(200, "success", result);
    }

    @RequestMapping("/talent/delete/{id}")
    public Result<?> deleteTalentById(@PathVariable int id){
        int result = talentMapper.deleteById(id);
        return new Result<>(200, "success", result);
    }
}
